<template>
  <a-card
    :bodyStyle="{
      height: '100%'
    }"
  >
    <CommonUpload :data="data" :showFileList="false" :url="url" @success="success">
      <div class="text-center">
        <div class="text-[2rem]">
          <icon-upload />
        </div>
        <slot></slot>
        <div v-if="allowDownload">
          <a-link class="mt-4" type="link" @click.stop="download">{{ t["下载模板"] }}</a-link>
        </div>
      </div>
    </CommonUpload>
  </a-card>
</template>

<script setup lang="ts">
import { fileTemplate } from "@/api/service/utils";
import { FileItem, Message } from "@arco-design/web-vue";

const t = translate("公共模块");
const emit = defineEmits(["success"]);

const props = withDefaults(
  defineProps<{
    /* 下载和上传的URL */
    url: string;
    allowDownload?: boolean;
    data?: any;
  }>(),
  {
    allowDownload: true
  }
);

const success = (data: FileItem) => {
  const { msg } = data.response;
  Message.info(msg);
  emit("success", data);
};
const download = () => {
  fileTemplate(props.url);
};
</script>

<style lang="scss" scoped></style>
